//
//  Utils.h
//  TestPrj
//
//  Created by 朱铅峰 on 2019/12/9.
//  Copyright © 2019 Xing. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface Utils : NSObject

- (instancetype)sharedInstance;
+ (instancetype)sharedInstance;

//获取文本的高度
+ (CGSize)textSizeOfText:(NSString*)text fontSize:(CGFloat)fontSize width:(CGFloat)width;
+ (CGSize)textSizeOfText:(NSString *)text font:(UIFont*)font width:(CGFloat)width;
+ (CGSize)textSizeOfText:(NSString *)text attributes:(NSDictionary *)attributes width:(CGFloat)width;
+ (CGSize)textSizeOfAttributedAttr:(NSAttributedString *)attributedString width:(CGFloat)width;

//判断空字符
+ (BOOL)isEmptyString:(NSString *)str;

//去除字符空白
+ (NSString *)trimString:(NSString *)str;

//imageView
+ (UIImageView *)genImageViewWithFrame:(CGRect)frame;

//创建UILabel
+ (UILabel *)genLabelWithFrame:(CGRect)frame
                     textAlign:(NSInteger)textAlign
                      fontSize:(CGFloat)fontSize
                     textColor:(UIColor *)textColor;

//设置背景颜色圆角等
+ (void)resetView:(UIView*)view
          bgColor:(UIColor*)bgColor
     cornerRadius:(CGFloat)radius
      borderWidth:(CGFloat)bWidth
      borderColor:(UIColor*)bColor;

//为textField添加左边距
+ (void)setTextFieldLeftPadding:(UITextField *)textField
                       forWidth:(CGFloat)leftWidth;

//16进制颜色转rgb
+ (UIColor *)colorHexString:(NSString *)hexColor alpha:(float)opacity;
+ (UIColor *)colorRGB:(NSUInteger)hex alpha:(CGFloat)alpha;

//检查网络代理
+ (void)getProxyStatus:(void(^)(BOOL isProxy,NSString *hostName,NSString *portNum,NSString *proxyType))block;

//警告狂
+ (void) showAlertViewWithTitle:(NSString*)title
                        content:(NSString*)content
                    buttonTitle:(NSString *)buttonTitle
                       targetVC:(UIViewController *)targetVC;

/**
 保存到相册
 
 @param image 图片
 @param targetVC 目标
 @param completeSel 回调SEL,使用UIImageWriteToSavedPhotosAlbum中的SEL- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
 */
+ (void) saveToAlbumWithImage:(nonnull UIImage *)image
                     targetVC:(UIViewController *)targetVC
                  completeSel:(nullable SEL)completeSel;

//显示警告框
+ (void) showAlertWithTitle:(NSString*)title
                    content:(NSString*)content
                   targetVC:(UIViewController *)targetVC
               dismissBlock:(void(^)(NSInteger))dismissBlock
               cancelButton:(nonnull NSString *)cancelButton
               otherButtons:(NSArray *)otherButtons;

//获取截屏
+ (UIImage*)captureImageAtView:(UIView*)view;

//跳转web
+ (void)toWebVCWithUl:(NSString *)ul targetVC:(UIViewController *)vc;

//base64加解密
+ (NSString *)cBase64EncodeString:(NSString *)string;
+ (NSString *)cBase64DecodeString:(NSString *)string;

/**
 获取随机数
 
 @param from 开始l值
 @param to 结束值
 @return 随机数
 */
+ (int) randomNumberFrom:(int)from to:(int)to;

/**
 数值字符串至少为两位
 
 @param number 数值
 @return 字符串
 */
+ (NSString *)getTwoNumberStr:(NSInteger)number;

//生成唯一串
+ (NSString *)uniqueString;

//获取视频第一帧的截图方法
+ (UIImage *)getVideoPreviewImage:(NSString *)videoURL;




#pragma mark - 计算字符串宽高
+ (CGSize)sizeWithFont:(UIFont*)font Str:(NSString*)str withMaxWidth:(CGFloat)maxWidth;

+ (CGSize)sizeAttributedWithFont:(UIFont*)font Str:(NSMutableAttributedString*)str withMaxWidth:(CGFloat)maxWidth;


+ (NSString *)getImageDataBase64:(UIImage *)image;

+ (NSMutableAttributedString *)returnStringColor:(NSString *)string rang:(NSRange)rang color:(UIColor *)color;

+ (NSMutableAttributedString *)returnStringSize:(NSString *)string rang:(NSRange)rang size:(CGFloat)size;

@end

NS_ASSUME_NONNULL_END
